/*
* UserController.java
* Created on  2013-9-26 下午10:42
* 版本       修改时间          作者      修改内容
* V1.0.1    2013-9-26       yutong    初始版本
*
*/
package com.genghis.ptas.web.tourists;


import com.genghis.ptas.scorm.entity.ScormInfo;
import com.genghis.ptas.scorm.service.UpScormService;
import com.genghis.ptas.scorm.service.ValidateImageService;
import com.genghis.ptas.security.entity.User;
import com.genghis.ptas.security.service.UserService;
import com.genghis.ptas.system.entity.DictValues;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author yutong
 * @version 1.0.1
 */
@Controller
@Transactional
@RequestMapping("/tourist/")
public class TouristsController {

    @Autowired
    private UserService userService;

    @Autowired
    private UpScormService upScormService;

    @Autowired
    private ValidateImageService validateImageService;
    @RequestMapping(value = "registerDo", method = {RequestMethod.GET})
    public String register(HttpServletRequest request) {
        return "tourist/register";
    }
    @RequestMapping(value = "addUser", method = {RequestMethod.POST})
    @ResponseBody
    public void addUser(User user) {
        userService.addUser(user);
    }
    @RequestMapping(value = "sortDo", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public  List<DictValues> sortDo(HttpServletRequest request) {
        List<DictValues> courseType= userService.findAllCourseType();

        return  courseType ;
    }

    @RequestMapping(value = "listAllScormInfo", method = {RequestMethod.GET})
    public String listAllScormInfo(HttpServletRequest request) {

        List<ScormInfo> scormInfoList=  upScormService.findScormInfoPageList() ;
        request.setAttribute("scormInfoList",scormInfoList);
        return "consumer/usermain";
    }
    @RequestMapping(value = "calendar", method = {RequestMethod.GET})
    public String calendar(HttpServletRequest request) {
        return "consumer/calendar";
    }
    @RequestMapping(value = "showImage")
    @ResponseBody
    public void showImage(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        validateImageService.validateImage(request,response);
    }
    @RequestMapping(value = "checkRepeatImageCode", method = {RequestMethod.POST})
    @ResponseBody
    public boolean checkRepeatImageCode(@RequestParam("imageCode") String imageCode) {
        return validateImageService.checkImageCode(imageCode);
    }
    @RequestMapping(value = "courseType", method = {RequestMethod.GET})
    public String courseType(@RequestParam("courseType") int courseType,HttpServletRequest request) {
        List<ScormInfo> scormList=  upScormService.listAllScormByCourseType(courseType);
        request.setAttribute("scormList",scormList);
        return "tourist/listScormByCourseType";
    }
}
